<template>
  <div class="dialog">
    <el-dialog
      title="审核未通过原因"
      :visible.sync="showDialog"
      width="35%"
      top="0"
      :close-on-click-modal="false"
      @close="cancel"
    >
      <el-form
        ref="ruleForm"
        label-position="left"
        :model="formData"
        :rules="rules"
        class="el-form"
      >
        <el-form-item
          label="未通过原因："
          class="w100p"
          prop="reason"
        >
          <el-input
            v-model="formData.reason"
            clearable
            :rows="2"
            type="textarea"
            placeholder="请输入未通过原因"
          />
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          class="cancelbtn"
          @click="cancel()"
        >取 消</el-button>
        <el-button
          type="primary"
          class="savebtn"
          @click="save('ruleForm')"
        >保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import scrapAuditApi from "@/api/equip-repair-manage/destory-manage/index";

// import outsourcedRepairAuditApi from "@/api/equip-repair-manage/outsourced-repair-audit";

export default {
  name: "",
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false
    },
    editObject: {
      type: [Object],
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      formData: {},
      rules: {
        reason: [
          {
            required: true,
            message: "请输入未通过原因",
            trigger: ["change", "blur"]
          }
        ]
      },
      showDialog: this.show
    };
  },

  watch: {
    show(v) {
      this.showDialog = v;
      if (v) {
        var day = new Date();
        this.formData.time = this.$moment(day).format("YYYY-MM-DD");
        this.$nextTick(() => {
          this.$refs['ruleForm']?.clearValidate();
        });
      }
    }
  },
  created() {},
  mounted() {},
  methods: {
    save(formData) {
      this.$refs[formData].validate(valid => {
        if (valid) {
          // 审核不通过
          this.formData.result = "审核未通过";
          this.formData.hitchApplyAuditCode = this.editObject.hitchApplyAuditCode;
          scrapAuditApi
            .scrapAuditNew({
              ...this.formData,
              personNo: sessionStorage.personNo,
              pass: false
            })
            .then(res => {
              if (res.code === 1) {
                this.$message.success("审核成功！");
                this.close();
              } else {
                this.$message.error("审核失败！");
              }
            });
        } else {
          return false;
        }
      });
    },
    close() {
      this.formData = {};
      this.$emit("closeDialog");
    },
    cancel() {
      this.formData = {};
      this.$emit("cancelDialog");
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
